package cn.hgj.controller;

import cn.hgj.service.OrderService;
import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

//@RestController
@RequestMapping("/payment")
@RequiredArgsConstructor
public class PaymentController {
    private final OrderService orderService;

    @PostMapping("/callback")
    public ResponseEntity<String> paymentCallback(@RequestBody JSONObject request) {
        orderService.handlePaymentCallback(
                request.getString("orderId"),
                true,request.getString("paymentId"),
                LocalDateTime.now()
        );
        return ResponseEntity.ok("Callback processed");
    }
}
